package com.areaCalc;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class AreaCalcHelper extends SQLiteOpenHelper {
	private static final String DATABASE_NAME="areaCalc.db";
	private static final int SCHEMA_VERSION=1;

	public AreaCalcHelper(Context context) {
		super(context, DATABASE_NAME, null, SCHEMA_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL("CREATE TABLE calc (_id INTEGER PRIMARY KEY AUTOINCREMENT," +
		"name TEXT, value TEXT, type TEXT);");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub

	}

	public void insert(String name, String value, String type) {
		ContentValues cv = new ContentValues();

		cv.put("name",name);
		cv.put("value", value);
		cv.put("type", type);

		getWritableDatabase().insert("calc", "name", cv);
	}

	public Cursor getAll() {
		return (getReadableDatabase().rawQuery("SELECT _id, name, value, type FROM calc", null));
	}

	public String getName(Cursor c) {
		return c.getString(1);
	}

	public String getAddress(Cursor c) {
		return(c.getString(2));
	}
	public String getType(Cursor c) {
		return(c.getString(3));
	}
	public String getNotes(Cursor c) {
		return(c.getString(4));
	}

}
